package com.jiangjiang.eshop.auth.facade;

import com.jiangjiang.eshop.auth.convert.AccountPriorityRelationShipConvert;
import com.jiangjiang.eshop.auth.dto.AccountPriorityRelationshipDTO;
import com.jiangjiang.eshop.auth.service.AccountPriorityRelationShipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @ClassName AccountPriorityRelationshipFacade
 * @Description TODO
 * @Author jhw
 * @Date 2021/7/7 5:41
 * @Version 1.0
 **/
@Component
public class AccountPriorityRelationshipFacade {
    @Autowired
    private AccountPriorityRelationShipService accountPriorityRelationShipService;
    @Autowired
    private AccountPriorityRelationShipConvert accountPriorityRelationShipConvert;

    /**
     * 根据用户账户id查询权限和账户之间的关系
     * @param accountId
     * @return 查询结果
     */
    public List<AccountPriorityRelationshipDTO> queryPriorityRelationsByAccountId(Long accountId) {
        return accountPriorityRelationShipConvert.convertEntity2DTO(
                accountPriorityRelationShipService.queryPriorityRelationsByAccountId(accountId)
        );
    }

    /**
     * 保存账号和权限之间的关系
     * @param priorityRelations
     */
    public void saveRelationShip(List<AccountPriorityRelationshipDTO> priorityRelations) {
        accountPriorityRelationShipService.saveBatch(accountPriorityRelationShipConvert.convertDTO2Entity(priorityRelations));
    }

    /**
     * 账号和权限之间的关系更新
     * @param priorityRelations
     */
    public void relationShipUpdate(List<AccountPriorityRelationshipDTO> priorityRelations) {
        accountPriorityRelationShipService.updateBatchById(accountPriorityRelationShipConvert.convertDTO2Entity(priorityRelations));

    }
}
